package org.light.reflecttable.serviceimpl;

import java.sql.Connection;
import java.util.List;

import org.light.reflecttable.dao.FieldDao;
import org.light.reflecttable.daoimpl.FieldDaoImpl;
import org.light.reflecttable.database.DBConf;
import org.light.reflecttable.domain.Field;
import org.light.reflecttable.service.FieldService;

public class FieldServiceImpl implements FieldService{
	protected FieldDao dao = new FieldDaoImpl();

	@Override
	public List<Field> listAllTableFieldsByTableName(String tableName) throws Exception {
		try (Connection connection = DBConf.initDB(TableServiceImpl.dbHost,TableServiceImpl.dbPort,TableServiceImpl.dbName,TableServiceImpl.userName,TableServiceImpl.password)) {
			return dao.listAllTableFieldsByTableName(connection,tableName,TableServiceImpl.dbName);
		}
	}
	
	@Override
	public List<Field> listAllPgTableFieldsByTableName(String tableName) throws Exception {
		try (Connection connection = DBConf.initPgDB(TableServiceImpl.dbHost,TableServiceImpl.dbPort,TableServiceImpl.dbName,TableServiceImpl.userName,TableServiceImpl.password)) {
			return dao.listAllPgTableFieldsByTableName(connection,tableName);
		}
	}
}
